package com.smyx.config;

import com.smyx.bean.TestProperties;
import com.smyx.service.StudentService;
import com.smyx.service.UserService;
import com.smyx.service.impl.StudentServiceImpl;
import com.smyx.service.impl.UserServiceImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

// 定义一个配置类
@Configuration
// 如果只配置@ConfigurationProperties注解，在IOC容器中是获取不到properties配置文件转化的bean的，
// 必须在此处加上@EnableConfigurationProperties({TestProperties.class})
// TestProperties.class 会读取yml中对应的开头定义的属性 转换bean对象
@EnableConfigurationProperties({TestProperties.class})
public class SmyxAutoConfiguration {

    private final TestProperties testProperties;

    public SmyxAutoConfiguration(TestProperties testProperties) {
        this.testProperties = testProperties;
    }

    @Bean
    public UserService userService() {
        return new UserServiceImpl(testProperties);
    }
    @Bean
    public StudentService studentService() {
        return new StudentServiceImpl(testProperties);
    }
}
